﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pseudogenerator.Common.Generators;
using Pseudogenerator.Common.ViewModels.Core;

namespace Pseudogenerator.Common.ViewModels
{
   public class GreenViewModel:WorkSpaceViewModel<Green>
    {
       public GreenViewModel()
        {
            ModeloActual = new Green();
        }

       #region ModelFields

       public uint m
       {
           get
           {
               return ModeloActual.m;
           }
           set
           {
               if (ModeloActual.m == value)
                   return;
               ModeloActual.m = value;
               OnPropertyChanged();
               RefreshGUI();
           }
       }

       public uint k
       {
           get
           {
               return ModeloActual.k;
           }
           set
           {
               if (ModeloActual.k == value)
                   return;
               ModeloActual.k = value;
               OnPropertyChanged();
               RefreshGUI();
           }
       }
       #endregion
       public override bool CanRun
       {
           get
           {
               return ModeloActual.CanGenerateNext && !InWorkProgress;
           }
       }

       private Green _ModeloActual = null;
       public override Green ModeloActual
       {
           get
           {
               if (_ModeloActual == null)
                   _ModeloActual = new Green();

               return _ModeloActual;
           }
           set
           {
               if (value == null)
                   return;
               this.k = value.k;
               this.m = value.m;
           //    this.x_1 = value.Anterior;
               ClearCommand.Execute(null);
           }
       }

       public override string Title
       {
           get { return "Green"; }
       }

       public override IEnumerable<string> Errors
       {
           get {
                   if (k<16)
                       yield return "'k' debe ser mayor que 15";
                   if(m<k)
                       yield return "'m' debe ser mayor que 'k'";
           }
       }

       public override IEnumerable<string> Recommendations
       {
           get { return new List<string>(); }
       }

       protected override void AddPreload()
       {

           var actual = Preloads.FirstOrDefault(i => i.k == k && i.m == m);
           if (actual == null) {
               Preloads.Add(new Green() {k =k , m = m });
           }
       }
    }
}
